#include <map>
#include <iostream>
#include <vector>

using namespace std;

// Parameters:
//        numbers:     an array of integers
//        length:      the length of array numbers
//        duplication: (Output) the duplicated number in the array number
// Return value:       true if the input is valid, and there are some duplications in the array number
//                     otherwise false
bool duplicate(int numbers[], int length, int* duplication) {
	if (length < 2) return false;
	bool isRep = false;
	map<int,int> m;
	int cnt = 0;
	for (int i = 0; i < length; ++i)
	{
		++m[numbers[i]];
		if (m[numbers[i]] == 2)
		{
			duplication[cnt] = numbers[i];
			++cnt;
			isRep = true;
		}
	}
	
	return isRep;
}


//int main()
//{
//	int a[] = { 2,1,3,1,4 }, len = 5;
//	//vector<int> v;
//	int b[7];
//	bool rep = duplicate(a, len,b );
//	cout << rep;
//	for (auto i : b)
//		cout << i << " ";
//	cout << endl;
//	system("pause");
//	return 0;
//}